package com.verlet.web.controller;

import com.verlet.web.fegin.NacosFeignService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@Slf4j
@RestController
public class Controller {

    @Autowired
    private NacosFeignService nacosFeignService;

    @Autowired
    @Qualifier("httpRestTemplate")
    private RestTemplate restTemplate;

    @RequestMapping("/nacosName/{id}")
    public String nacosName(@PathVariable("id") String id, HttpServletRequest request) {
        log.info("id= {}", id);
        log.info("{} , Header= {}", request.getRequestURI(), request.getHeader("name"));
        return nacosFeignService.getConfig();
    }

    @RequestMapping("/nacosNameById")
    public String nacosNameById(@RequestParam String id, HttpServletRequest request) {
        log.info("id= {}", id);
        log.info("{} , Header= {}", request.getRequestURI(), request.getHeader("name"));
        return nacosFeignService.getNacosApplicationName();
    }

    @RequestMapping("/authFilter/user")
    public String authFilterUser(String token, String uid) {
        log.info("token={}, uid={}", token, uid);
        return "SUCCESS";
    }

    @RequestMapping("/authorizeFilter/user")
    public String authorizeFilterUser(String token, String uid) {
        log.info("token={}, uid={}", token, uid);
        return "SUCCESS";
    }

    @RequestMapping(value = "/a/t")
    public String restTempleTest() {
        String result = restTemplate.getForObject("https://www.baidu.com/", String.class);
        log.info(result);
        return result;
    }

}
